package com.gaoda.booksystem.mapper;

import com.gaoda.booksystem.entity.Book;
import com.gaoda.booksystem.entity.Borrowing;
import com.gaoda.booksystem.entity.Revert;
import com.gaoda.booksystem.entity.User;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author: LuckyBear
 * @date: 2018-12-12 9:31
 * @description:
 */
@Component
public interface UserMapper {

    //添加用户
    int insert(User user);

    //通过用户账号查找用户
    User findUserByName(String username);

    //修改用户信息
    void updateUser(User user);

    //修改用户密码
    void updatePwd(User user);

    //通过书籍编号查找书籍
    Book findBookByNumber(String bookNumber);


    //模糊查询 + 分页
    List<Book> findBooks(@Param("bookName") String bookName,
                         @Param("bookPublishers") String bookPublishers,
                         @Param("bookType") String bookType,
                         @Param("currentPage") int currentPage,
                         @Param("pageCount") int pageCount
    );

    //获得总页数
    int getTotal(@Param("bookName") String bookName,
                 @Param("bookPublishers") String bookPublishers,
                 @Param("bookType") String bookType);

    //我的书籍页面分页
    List<Borrowing> myBooks(String userNumber);

    //借书
    int borrowingBook(Borrowing borrowing);

    //借书后改变书籍余量
    void updateBookNumLess(String bookNumber);

    //还书
    int revertBook(Revert revert);
    void updateBookFlag(Borrowing borrowing);

    //更新书籍余量
    void updateBookNumMore(String bookNumber);

    //查询该用户借阅该书的记录
    List<Borrowing> findBorrowing(Borrowing borrowing);

    //查询表中该用户的借阅情况
    List<Borrowing> findBorrowingBook(Borrowing borrowing);

    //查询该书最新借阅状态
    List<Borrowing> queryBorrowing(String bookNumber);

    //遍历所有图书
    List<Book> AllBook();

}
